{include file="public/header" /}
<div class="header">
	<a href="{$config['admin_route']}Bew/configvalue">
		<span style="background:#999;">项目配置</span>
	</a>
	<span>配置管理</span>
	<div></div>
</div>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<div class="layui-btn-group">
			<button type="button" class="layui-btn layui-btn-primary" lay-event="add">
				<i class="layui-icon layui-icon-add-1"></i>添加
			</button>
			<button type="button" class="layui-btn layui-btn-primary" lay-event="edit">
				<i class="layui-icon layui-icon-edit"></i>修改
			</button>
			<button type="button" class="layui-btn layui-btn-primary" lay-event="del">
				<i class="layui-icon layui-icon-delete"></i>删除
			</button>
		</div>
	</div>
</script>
<table class="layui-hide" id="lists" lay-filter="lists"></table>
<script type="text/javascript">
	layui.use(['layer','table'],function(){
		table = layui.table;
		layer = layui.layer;
		$ = layui.jquery;
		get_data();
		
		table.on('row(lists)',function(obj){
			obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
			obj.tr.find("div.layui-unselect.layui-form-radio")[0].click();
		});
		table.on('toolbar(lists)',function(obj){
			var checkStatus = table.checkStatus(obj.config.id);
			var data = checkStatus.data;  //获取选中行数据
			switch(obj.event){
				case 'add':
					layer.full(layer.open({
						title: '添加',
						type: 2,
						content: '{$config["admin_route"]}bew/configadd',
						maxmin: true,
						area: ['70%','70%'],
						btn: ['确定','关闭'],
						yes: function(index,layero){
							var form = layero.find('iframe')[0].contentWindow;
							var button = {
								config_name : form.config_name.value,
								config_info : form.config_info.value,
								config_type : form.config_type.value,
								config_desc : form.config_desc.value,
								config_sort : form.config_sort.value,
								config_status : form.config_status.value
							};
							$.post('{$config["admin_route"]}bew/configadd',button,function(res){
								if(res.code>0){
									layer.msg(res.msg,{'icon':2});
								}else{
									layer.msg(res.msg,{'icon':1});
									get_data();
									layer.close(index);
								}
							},'json');
						}
					}))
					break;
				case 'edit':
					layer.full(layer.open({
						title: '修改',
						type: 2,
						content: '{$config["admin_route"]}bew/configedit?config_id='+data[0].config_id,
						maxmin: true,
						area: ['70%','70%'],
						btn: ['确定','关闭'],
						yes: function(index,layero){
							var form = layero.find('iframe')[0].contentWindow;
							var button = {
								config_id : data[0].config_id,
								config_name : form.config_name.value,
								config_info : form.config_info.value,
								config_type : form.config_type.value,
								config_desc : form.config_desc.value,
								config_sort : form.config_sort.value,
								config_status : form.config_status.value
							};
							$.post('{$config["admin_route"]}bew/configedit',button,function(res){
								if(res.code>0){
									layer.msg(res.msg,{'icon':2});
								}else{
									layer.msg(res.msg,{'icon':1});
									get_data();
									layer.close(index);
								}
							},'json');
						}
					}))
					break;
				case 'del':
					if(!data[0]){
						layer.msg('请选择一条数据',{'icon':2});
						return false;
					}
					layer.confirm('确定要删除吗？',{
						icon:3,
						btn: ['确定','取消']
					},function(){
						$.post('{$config["admin_route"]}bew/configdel',{'config_id':data[0].config_id},function(res){
							if(res.code>0){
								layer.alert(res.msg,{icon:2});
							}else{
								layer.msg(res.msg);
								get_data();
							}
						},'json');
					});
				break;
			};
		});
		function get_data(){
			table.render({
				elem : '#lists'
				,method : 'post'
				,url:"{$config['admin_route']}bew/configlist"
				,toolbar: '#toolbar'
				,defaultToolbar: ['filter']
				,title: '项目列表'
				,page: true
				,cols: [[
					{type:'radio'}
					,{field:'config_sort', width:'80', title:'排序'}
					,{field:'config_id', width:'80', title:'No'}
					,{field:'config_name', width:'150', title:'关键词'}
					,{field:'config_info', width:'150', title:'作用'}
					,{field:'config_desc', width:'300', title:'说明'}
					,{field:'config_status', width:'80', title:'状态',templet:function(res){
						if(res.config_status == 1){
							return '<span style="color:green;">开启</span>';
						}else{
							return '<span style="color:grey;">关闭</span>';
						}
					}}
				]]
				,data:[]
				,limit :10
				,limits:[10,20,30]
				,height: 'full-100'
			});
		}
	});
</script>
{include file="public/tail" /}